﻿using Glue;
using Xunit;

namespace GlueTests.MapperTests
{
    public class When_adding_creators
    {
        public class APerson{}
        public class AnotherPerson { }
        
        [Fact]
        public void Creators_added_to_mapping_Should_override_other_creators_towardsLeft()
        {
            var mappingCreatorWasCalled = false;
            var otherCreatorWasCalled = false;
            var mapping = new Mapping<APerson, AnotherPerson>(x => { 
                mappingCreatorWasCalled = true;
                return new APerson();
            },null);
            mapping.AddCreator(typeof(APerson), x=> {
                otherCreatorWasCalled = true;
                return new APerson();
            });
            mapping.Map(new AnotherPerson());
            Assert.True(mappingCreatorWasCalled);
            Assert.False(otherCreatorWasCalled);
        }

        [Fact]
        public void Creators_added_to_mapping_Should_override_other_creators_towardsRight()
        {
            var mappingCreatorWasCalled = false;
            var otherCreatorWasCalled = false;
            var mapping = new Mapping<APerson, AnotherPerson>(null,x =>
            {
                mappingCreatorWasCalled = true;
                return new AnotherPerson();
            });
            mapping.AddCreator(typeof(AnotherPerson), x =>
            {
                otherCreatorWasCalled = true;
                return new AnotherPerson();
            });
            mapping.Map(new APerson());
            Assert.True(mappingCreatorWasCalled);
            Assert.False(otherCreatorWasCalled);
        }
    }
}
